t = int(input())
for _ in range(t):
n = int(input())
arr = [int(x) for x in input().split()]
s = input()
d = {}
flag = True
for i in range(n):
if arr[i] not in d:
d[arr[i]] = s[i]
else:
if d[arr[i]] == s[i]:
continue
else:
flag = False
break
if flag:
print('YES')
else:
print('NO')
#include<bits/stdc++.h>
using namespace std;
#define cisws cin.tie (0); ios::sync_with_stdio (false); cout.tie(0);
#define ll long long
const int N = 1e5 + 7, mod = 1e9 + 7;
int n, t, m;
ll a[N], b[N];
void solve()
{
char c[80];
cin >> n;
for(int i = 1; i <= n; i ++){
cin >> a[i];
}
for(int i = 1; i <= n; i ++){
cin >> c[i];
}
for(int i = 1; i <= n; i ++){
for(int j = i + 1; j <= n; j ++){
if(a[i] == a[j] && c[i] != c[j]){
cout << "NO" << '\n';
return ;
}
}
}
cout << "YES" << '\n';
}
int main()
{
cisws
cin >> t;
while(t--)
{
solve();
}
}
1478A - Nezzar and Colorful Balls | 1581B - Diameter of Graph |
404A - Valera and X | 908A - New Year and Counting Cards |
146A - Lucky Ticket | 1594C - Make Them Equal |
1676A - Lucky | 1700B - Palindromic Numbers |
702C - Cellular Network | 1672C - Unequal Array |
1706C - Qpwoeirut And The City | 1697A - Parkway Walk |
1505B - DMCA | 478B - Random Teams |
1705C - Mark and His Unfinished Essay | 1401C - Mere Array |
1613B - Absent Remainder | 1536B - Prinzessin der Verurteilung |
1699B - Almost Ternary Matrix | 1545A - AquaMoon and Strange Sort |
538B - Quasi Binary | 424A - Squats |
1703A - YES or YES | 494A - Treasure |
48B - Land Lot | 835A - Key races |
1622C - Set or Decrease | 1682A - Palindromic Indices |
903C - Boxes Packing | 887A - Div 64 |